package online.westonline.com.westonline.entry;

import android.annotation.SuppressLint;

import com.alamkanak.weekview.WeekViewEvent;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日程Module
 */
@Entity
public class EventModel{
    @Id(autoincrement = true)
    private Long id;
    //只能用来查询
    @Property
    private String uuid;
    @Property
    private String mName;//标题
    @Property
    private String mStartTime;//开始时间
    @Property
    private String mEndTime;//结束时间
    @Property
    private int mColor;//日程背景色
    @Property
    private String moduleName;//模块名称
    @Property
    private String date;//日期
    private String f1;//保留字段
    private String f2;//保留字段
    private String f3;//保留字段
    @Property
    private int year;//年
    @Property
    private int month;
    @Property
    private int day;
    @Property
    private boolean mAllday;
    private boolean mAllsee;
    @Property
    private boolean mAlertSwitch;
    private boolean mMisuSwitch;

    @SuppressLint("SimpleDateFormat")
    public WeekViewEvent toWeekViewEvent(){

        String start_time = getDate()+" "+getMStartTime();
        String end_time = getDate()+" "+getMEndTime();
        // Parse time.
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date start = new Date();
        Date end = new Date();
        //再这里转换
        try {
            start = sdf.parse(start_time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        try {
            end = sdf.parse(end_time);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        // Initialize start and end time.
        Calendar now = Calendar.getInstance();
        now.setTime(start);
        Calendar startTime = (Calendar) now.clone();
        startTime.setTimeInMillis(start.getTime());
        startTime.set(Calendar.YEAR, now.get(Calendar.YEAR));
        startTime.set(Calendar.MONTH, now.get(Calendar.MONTH));
        startTime.set(Calendar.DAY_OF_MONTH, getDay());
        Calendar endTime = (Calendar) startTime.clone();
        endTime.setTimeInMillis(end.getTime());
        endTime.set(Calendar.YEAR, startTime.get(Calendar.YEAR));
        endTime.set(Calendar.MONTH, startTime.get(Calendar.MONTH));
        endTime.set(Calendar.DAY_OF_MONTH, startTime.get(Calendar.DAY_OF_MONTH));

        // Create an week view event.
        WeekViewEvent weekViewEvent = new WeekViewEvent();
        weekViewEvent.setName(getMName());
        weekViewEvent.setStartTime(startTime);
        //这啥？
        weekViewEvent.setLocation("西油online");
        weekViewEvent.setEndTime(endTime);
        weekViewEvent.setAllDay(mAllday);
        weekViewEvent.setId(id);
        weekViewEvent.setColor(mColor);
        //weekViewEvent.setColor(Color.parseColor(getColor()));

        return weekViewEvent;
    }
    @Generated(hash = 103296195)
    public EventModel(Long id, String uuid, String mName, String mStartTime,
            String mEndTime, int mColor, String moduleName, String date, String f1,
            String f2, String f3, int year, int month, int day, boolean mAllday,
            boolean mAllsee, boolean mAlertSwitch, boolean mMisuSwitch) {
        this.id = id;
        this.uuid = uuid;
        this.mName = mName;
        this.mStartTime = mStartTime;
        this.mEndTime = mEndTime;
        this.mColor = mColor;
        this.moduleName = moduleName;
        this.date = date;
        this.f1 = f1;
        this.f2 = f2;
        this.f3 = f3;
        this.year = year;
        this.month = month;
        this.day = day;
        this.mAllday = mAllday;
        this.mAllsee = mAllsee;
        this.mAlertSwitch = mAlertSwitch;
        this.mMisuSwitch = mMisuSwitch;
    }
    @Generated(hash = 1307476520)
    public EventModel() {
    }
    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getUuid() {
        return this.uuid;
    }
    public void setUuid(String uuid) {
        this.uuid = uuid;
    }
    public String getMName() {
        return this.mName;
    }
    public void setMName(String mName) {
        this.mName = mName;
    }
    public String getMStartTime() {
        return this.mStartTime;
    }
    public void setMStartTime(String mStartTime) {
        this.mStartTime = mStartTime;
    }
    public String getMEndTime() {
        return this.mEndTime;
    }
    public void setMEndTime(String mEndTime) {
        this.mEndTime = mEndTime;
    }
    public int getMColor() {
        return this.mColor;
    }
    public void setMColor(int mColor) {
        this.mColor = mColor;
    }
    public String getModuleName() {
        return this.moduleName;
    }
    public void setModuleName(String moduleName) {
        this.moduleName = moduleName;
    }
    public String getDate() {
        return this.date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public String getF1() {
        return this.f1;
    }
    public void setF1(String f1) {
        this.f1 = f1;
    }
    public String getF2() {
        return this.f2;
    }
    public void setF2(String f2) {
        this.f2 = f2;
    }
    public String getF3() {
        return this.f3;
    }
    public void setF3(String f3) {
        this.f3 = f3;
    }
    public int getYear() {
        return this.year;
    }
    public void setYear(int year) {
        this.year = year;
    }
    public int getMonth() {
        return this.month;
    }
    public void setMonth(int month) {
        this.month = month;
    }
    public int getDay() {
        return this.day;
    }
    public void setDay(int day) {
        this.day = day;
    }
    public boolean getMAllday() {
        return this.mAllday;
    }
    public void setMAllday(boolean mAllday) {
        this.mAllday = mAllday;
    }
    public boolean getMAllsee() {
        return this.mAllsee;
    }
    public void setMAllsee(boolean mAllsee) {
        this.mAllsee = mAllsee;
    }
    public boolean getMAlertSwitch() {
        return this.mAlertSwitch;
    }
    public void setMAlertSwitch(boolean mAlertSwitch) {
        this.mAlertSwitch = mAlertSwitch;
    }
    public boolean getMMisuSwitch() {
        return this.mMisuSwitch;
    }
    public void setMMisuSwitch(boolean mMisuSwitch) {
        this.mMisuSwitch = mMisuSwitch;
    }

}
